﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMS.IRepository;

namespace CMS.Controller
{
    public class Controller
    {
        Factory.Factory factory = new Factory.Factory();
        /// <summary>
        /// Gets all courses.
        /// </summary>
        /// <returns>List of CourseModel</returns>
        public List<CMS.Model.Course> GetAllCourses(int pageIndex, int pageSize,out int rowCount)
        {
            ICourseRepository iCourseRepository = factory.CreateCourseRepository();
            return iCourseRepository.SelectAllCourses(pageIndex,pageSize,out rowCount);
        }
        /// <summary>
        /// Gets courses by condition
        /// </summary>
        /// <param name="courseName">string courseName</param>
        /// <param name="courseStatus">bool courseStatus</param>
        /// <returns>List of CourseModel</returns>
        public List<CMS.Model.Course> GetCoursesByCondition(string courseName, string courseStatus, int pageIndex, int pageSize, out int rowCount)
        {
            ICourseRepository iCourseRepository = factory.CreateCourseRepository();
            return iCourseRepository.SelectCoursesByCondition(courseName,courseStatus,pageIndex,pageSize,out rowCount);
        }
        /// <summary>
        /// Deletes course by Id
        /// </summary>
        /// <param name="courseId">int courseId</param>
        public void DeleteCourseById(int courseId)
        {
            ICourseRepository iCourseRepository = factory.CreateCourseRepository();
            iCourseRepository.DeleteCourseById(courseId);
        }
        /// <summary>
        /// Updates courseStatus to false
        /// </summary>
        /// <param name="course">CourseModel course</param>
        public void UpdateCourseStatus(CMS.Model.Course course)
        {
            ICourseRepository iCourseRepository = factory.CreateCourseRepository();
            iCourseRepository.UpdateCourseStatus(course);
        }
        /// <summary>
        /// Gets all levels from database.
        /// </summary>
        /// <returns>List of LevelModel.</returns>
        public List<CMS.Model.Level> GetAllLevels()
        {
            ILevelRepository iLevelRepository = factory.CreateLevelRepository();
            return iLevelRepository.SelectAllLevels();
        }

        /// <summary>
        /// Gets all students.
        /// </summary>
        /// <returns>List of Student</returns>
        /// <remarks>RebeccaNiu</remarks>
        public List<CMS.Model.Student> GetAllStudents(int pageIndex,int pageSize,out int rowCount)
        {
            IStudentRepository studentRespository = factory.CreateStudentRepository();
            return studentRespository.SelectAllStudents(pageIndex, pageSize,out rowCount);
        }

        /// <summary>
        /// Gets the student by id.
        /// </summary>
        /// <param name="studentId">The student id.</param>
        /// <returns>Model of Student</returns>
        /// <remarks>RebeccaNiu</remarks>
        public CMS.Model.Student GetStudentById(int studentId)
        {
            IStudentRepository studentRespository = factory.CreateStudentRepository();
            return studentRespository.SelectStudentById(studentId);
        }

        /// <summary>
        /// Adds the student.
        /// </summary>
        /// <param name="student">The student.</param>
        /// <remarks>RebeccaNiu</remarks>
        public void AddStudent(CMS.Model.Student student)
        {
            IStudentRepository studentRespository = factory.CreateStudentRepository();
            studentRespository.InsertStudent(student);
        }

        /// <summary>
        /// Updates the student.
        /// </summary>
        /// <param name="student">The student.</param>
        /// <remarks>RebeccaNiu</remarks>
        public void UpdateStudent(CMS.Model.Student student)
        {
            IStudentRepository studentRespository = factory.CreateStudentRepository();
            studentRespository.UpdateStudent(student);

        }
        /// <summary>
        /// Deletes the student by id.
        /// </summary>
        /// <param name="studentId">The student id.</param>
        /// <remarks>RebeccaNiu</remarks>
        public void DeleteStudentById(int studentId)
        {
            IStudentRepository studentRespository = factory.CreateStudentRepository();
            studentRespository.DeleteStudentById(studentId);
        }
        /// <summary>
        /// Gets all grades.
        /// </summary>
        /// <returns>List of Grade</returns>
        /// <remarks>RebeccaNiu</remarks>
        public List<CMS.Model.Grade> GetAllGrades()
        {
            IClassRepository classRespository = factory.CreateClassRepository();
            return classRespository.SelectAllGrades();
        }

        /// <summary>
        /// Gets all teachers.
        /// </summary>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="rowCount">The row count.</param>
        /// <returns></returns>
        public List<CMS.Model.Teacher> GetAllTeachers(int pageIndex, int pageSize, out int rowCount)
        {
            ITeacherRepository teacherRep = factory.CreateTeacherRepository();
            return teacherRep.SelectAllTeacher(pageIndex ,pageSize,  out rowCount);
        }
        /// <summary>
        /// Gets all teachers.
        /// </summary>
        /// <returns></returns>
        public List<CMS.Model.Teacher> GetAllTeachers()
        {
            ITeacherRepository teacherRep = factory.CreateTeacherRepository();
            return teacherRep.SelectAllTeacher();
        }
        /// <summary>
        /// Gets the teacher by id.
        /// </summary>
        /// <param name="teacherId">The teacher id.</param>
        /// <returns></returns>
        public List<CMS.Model.Teacher> GetTeacherById(int teacherId)
        {
            ITeacherRepository teacherRep = factory.CreateTeacherRepository();
            return teacherRep.SelectTeacherById(teacherId);
        }

        /// <summary>
        /// Adds the teacher.
        /// </summary>
        /// <param name="teacher">The teacher.</param>
        public void AddTeacher(CMS.Model.Teacher teacher)
        {
            ITeacherRepository teacherRep = factory.CreateTeacherRepository();
            teacherRep.InsertTeacher(teacher);
        }

        /// <summary>
        /// Updates the teacher.
        /// </summary>
        /// <param name="teacher">The teacher.</param>
        public void UpdateTeacher(CMS.Model.Teacher teacher)
        {
            ITeacherRepository teacherRep = factory.CreateTeacherRepository();
            teacherRep.UpdateTeacher(teacher);
        }

        /// <summary>
        /// Deletes the teacher by id.
        /// </summary>
        /// <param name="teacherId">The teacher id.</param>
        public void DeleteTeacherById(int teacherId)
        {
            ITeacherRepository teacherRep = factory.CreateTeacherRepository();
            teacherRep.DeleteTeacherById(teacherId);
        }

        /// <summary>
        /// Gets all departments.
        /// </summary>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <returns></returns>
        public List<CMS.Model.Department> GetAllDepartments(int pageIndex, int pageSize)
        {
            IDepartmentRepository departmentRep = factory.CreateDepartmentRepository();
            return departmentRep.SelectAllDepartment(pageIndex ,pageSize);

        }

        /// <summary>
        /// Gets all departments.
        /// </summary>
        /// <returns></returns>
        public List<CMS.Model.Department> GetAllDepartments()
        {
            IDepartmentRepository departmentRep = factory.CreateDepartmentRepository();
            return departmentRep.SelectAllDepartment();

        }

        /// <summary>
        /// Gets the department by id.
        /// </summary>
        /// <param name="departmentId">The department id.</param>
        /// <returns></returns>
        public List<CMS.Model.Department> GetDepartmentById(int departmentId)
        {
            IDepartmentRepository departmentRep = factory.CreateDepartmentRepository();
            return departmentRep.SelectDepartmentById(departmentId);
        }

        /// <summary>
        /// Adds the department.
        /// </summary>
        /// <param name="department">The department.</param>
        public void AddDepartment(CMS.Model.Department department)
        {
            IDepartmentRepository departmentRep = factory.CreateDepartmentRepository();
            departmentRep.InsertDepartment(department);
        }

        /// <summary>
        /// Updates the department.
        /// </summary>
        /// <param name="department">The department.</param>
        public void UpdateDepartment(CMS.Model.Department department)
        {
            IDepartmentRepository departmentRep = factory.CreateDepartmentRepository();
            departmentRep.UpdateDepartment(department);
        }

        /// <summary>
        /// Deletes the department by id.
        /// </summary>
        /// <param name="teacherId">The teacher id.</param>
        public void DeleteDepartmentById(int teacherId)
        {
            IDepartmentRepository departmentRep = factory.CreateDepartmentRepository();
            departmentRep.DeleteDepartmentById(teacherId);
        }
        /// <summary>
        /// Generates course report.
        /// </summary>
        /// <param name="condition">The Condition.</param>
        /// <returns>List of CourseListModel.</returns>
        public List<Model.CourseList> GenerateCourseReport(Model.Condition condition, int pageIndex, int pageSize, out int rowCount)
        {
            ICourseListRepository iCourseRepository = factory.CreateCourseListRepository();
            return iCourseRepository.SelectCourseByConditon(condition, pageIndex , pageSize, out rowCount);
        }
        /// <summary>
        /// Gets the students not in course.
        /// </summary>
        /// <param name="courseId">The course id.</param>
        /// <returns></returns>
        public List<Model.Student> GetStudentsNotInCourse(int courseId)
        {
            
            IStudentRepository studentRepository = factory.CreateStudentRepository();
            List<Model.Student> studentName = studentRepository.SelectStudentsNotInCourse(courseId);
            return studentName;
        }
        /// <summary>
        /// Gets the students in course.
        /// </summary>
        /// <param name="courseId">The course id.</param>
        /// <returns></returns>
        public List<Model.Student> GetStudentsInCourse(int courseId)
        {
            ;
            IStudentRepository studentRepository = factory.CreateStudentRepository();
            List<Model.Student> studentName = studentRepository.SelectStudentsInCourse(courseId);
            return studentName;
        }
        /// <summary>
        /// Adds the course.
        /// </summary>
        /// <param name="course">The course.</param>
        /// <returns></returns>
        public int AddCourse(Model.Course course)
        {
            
            ICourseRepository courseRepository = factory.CreateCourseRepository();
            int courseID = courseRepository.InsertCourse(course);
            return courseID;
        }
        /// <summary>
        /// Updates the course.
        /// </summary>
        /// <param name="course">The course.</param>
        public void UpdateCourse(Model.Course course)
        {
            
            ICourseRepository courseRepository = factory.CreateCourseRepository();
            courseRepository.UpdateCourse(course);
        }
        /// <summary>
        /// Adds the course details.
        /// </summary>
        /// <param name="coursedetails">The coursedetails.</param>
        public void AddCourseDetails(Model.CourseDetails coursedetails)
        {
            
            ICourseDetailRepository courseDetailsRepository = factory.CreateCourseDetailRepository();
            courseDetailsRepository.InsertCourseDetails(coursedetails);
        }
        /// <summary>
        /// Deletes all students by course id.
        /// </summary>
        /// <param name="couseId">The couse id.</param>
        public void DeleteAllStudentsByCourseId(int couseId)
        {
            
            ICourseDetailRepository courseDetailsRepository = factory.CreateCourseDetailRepository();
            courseDetailsRepository.DeleteCourseDetails(couseId);
        }
        /// <summary>
        /// Gets the course by id.
        /// </summary>
        /// <param name="courseId">The course id.</param>
        /// <returns></returns>
        public List<Model.Course> GetCourseById(int courseId)
        {
           
            ICourseRepository saveRepository = factory.CreateCourseRepository();
            List<Model.Course> courseName = saveRepository.SelectCourseName(courseId);
            return courseName;
        }

    }
}
